
use "${Gpath}\data\\diseases.dta" , clear 

estimates drop _all 
local h=1 

qui reg PCI predicted_hwoverlap  , cluster(sp_cnes) 
sum PCI  if e(sample)
scalar Mean=r(mean)
eststo M`h++', addscalars(Mean Mean )

qui reghdfe PCI predicted_hwoverlap, a(date_adm ) cluster(sp_cnes)
sum PCI  if e(sample)
scalar Mean=r(mean)
eststo M`h++', addscalars(Mean Mean )

qui reghdfe  PCI  predicted_hwoverlap  , a(date_adm sp_cnes) cluster(sp_cnes) 
sum PCI  if e(sample)
scalar Mean=r(mean)
eststo M`h++', addscalars(Mean Mean )

qui reghdfe  PCI $XVar0 predicted_hwoverlap  , a(date_adm sp_cnes) cluster(sp_cnes) 
sum PCI  if e(sample)
scalar Mean=r(mean)
eststo M`h++', addscalars(Mean Mean )

esttab M* using "${Gpath}\\table\\PCI_overlap_m.csv",  replace star(* 0.1 ** 0.05 *** 0.01) se b(4) staraux brackets   ///
compress   begin(";")  delimiter(";") end(";") keep(predicted_hwoverlap ) scalar(Mean N )


estimates drop _all 
local h=1 

probit PCI i.(uf ano_cmpt mes_cmpt) $XVar0_PCI  , cluster(sp_cnes)
margins , dydx( $XVar0_PCI ) post 
estimates store M`h++'

esttab M* using "${Gpath}\\table\\probit_model_PCI.csv",  replace star(* 0.1 ** 0.05 *** 0.01) se b(4) staraux brackets   ///
compress   begin(";")  delimiter(";") end(";") 

qui reg PCI i.(uf ano_cmpt mes_cmpt) $XVar0_PCI  , cluster(sp_cnes)
test $XVar0_PCI 

probit PCI i.(uf ano_cmpt mes_cmpt) $XVar0_PCI 

predict predict_pci, pr 
predict phat, xb

gen mills = exp(-.5*phat^2)/(sqrt(2*_pi)*normprob(phat))

bysort sp_cnes: egen mean_pci_cnes=mean(PCI)

keep n_aih sp_cnes mean_pci_cnes predict_pci mills 

saveold  "${Gpath}\data\\pci_propensity.dta", replace 
